﻿/*
 *Copyright (c) 2008, Scendix Software, Inc.
 * 
 */
using System;
using System.Collections.Generic;
using System.Text;
using SKYPE4COMLib;
using Microsoft.MediaCenter.UI;
using TapiRex;
using Microsoft.MediaCenter.Hosting;

namespace mceTapiRexv2
{
    public class ContactAttribute : ModelItem
    {
        private string key;
        private string value;
        private string callBy;

        public ContactAttribute(string key, string value)
        {
            this.key = key;
            this.value = value;
            this.callBy = null;
        }
        public ContactAttribute(string key, string value, string callBy)
        {
            this.key = key;
            this.value = value;
            this.callBy = callBy;
        }
        /// <summary>
        /// Method to either dial a number using TapiRex or initiating a Skype call
        /// </summary>
        public void callContact()
        {
            if (callBy == null)
                return;
            AddInHost.Current.MediaCenterEnvironment.Dialog("Trying to call", "Error", Microsoft.MediaCenter.DialogButtons.Ok, 40, true);
            switch (callBy)
            {
                case "skype":
                    SKYPE4COMLib.Command cmd = new SKYPE4COMLib.Command();

                    cmd.Command = "CALL " + this.value;

                    Skype mobjSkype = new Skype();
                    mobjSkype.SendCommand(cmd);
                    break;
                case "phone":
                    try
                    {
                        TapiRex.Helper TRexHelper = new TapiRex.Helper();
                        TapiRex.Application app = TRexHelper.GetApplication;
                        app.StartCall(this.value);
                    }
                    catch (Exception ex)
                    {

                        AddInHost.Current.MediaCenterEnvironment.Dialog(ex.Message,"Error",Microsoft.MediaCenter.DialogButtons.Ok,40,true);
                     }
                    break;
            }
        }
        /// <summary>
        /// checks whether this attribute is callable or an information like name, company
        /// </summary>
        /// <returns></returns>
        public bool isNumber()
        {
            if (callBy == "phone" || callBy == "skype")
                return true;
            else return false;
        }
        public bool canBeCalled
        {
            get{ return isNumber();}
            set { }

        }


        public string Key
        {
            get { return this.key; }
            set { this.key = value; }
        }
        public string CallBy
        {
            get { return this.callBy; }
            set { this.callBy = value; }
        }
        public string Value
        {
            get { return this.value; }
            set { this.value = value; }
        }
        public Image icon
        {
            get
            {
                if (callBy == "skype")
                    return new Image("resx://mceTapiRexv2/mceTapiRexv2.Resources/Skype_logo");
                else if (callBy == "phone")
                    return new Image("resx://mceTapiRexv2/mceTapiRexv2.Resources/AppIcon");
                else return null;
            }
            set { }
        }
    }
}